type Cause = Error | object | string;

export class HttpError extends Error {
  statusCode: number;
  cause: Cause | undefined;
  errorCode: string | undefined;
  constructor(message: string, statusCode: number, cause?: Cause, errorCode?: string) {
    super(message);
    this.statusCode = statusCode;
    this.cause = cause;
    this.errorCode = errorCode;
  }
}

export const payloadTooLargeError = (): HttpError =>
  new HttpError('payload too large', 413, undefined, 'PAYLOAD_TOO_LARGE');
